﻿//-----------------------------------------------------------------------
// <copyright file="UnityConfiguration.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 
namespace ChatBox.Engine
{
    using ChatBox.Engine.Log;
    using ChatBox.Engine.Settings;
    using ChatBox.Engine.Web;
    using ChatBox.Interfaces;

    using Microsoft.Practices.Unity;

    /// <summary>
    /// Configure a IOC container with types defined in this assembly
    /// </summary>
    public static class UnityConfiguration
    {
        /// <summary>
        /// Configure the mappings of interfaces to types
        /// for the IOC container
        /// </summary>
        /// <param name="container">the container to populate</param>
        public static void RegisterTypes(IUnityContainer container)
        {            
            // server connections
            container.RegisterType<IPublicChatDataSource, WebChatDataSource>();
            container.RegisterType<IPrivateChatDataSource, WebPrivateMessageSource>();
            container.RegisterType<IMessageDelete, WebMessageDelete>();
            container.RegisterType<IChatMessageSend, WebMessageSend>();

            container.RegisterType<ICoolNodesSource, WebCoolNodesSource>();
            container.RegisterType<IEditorCoolsSource, WebEditorCoolsSource>();
            container.RegisterType<IChatDataSource, WebChatDataSource>();
            container.RegisterType<ILatestVersionSource, WebLatestVersionSource>();
            container.RegisterType<IChatMessageSend, WebMessageSend>();
            container.RegisterType<INewWriteupsSource, WebNewWriteupSource>();
            container.RegisterType<IOtherUsersSource, WebOtherUsersSource>();
            container.RegisterType<IRandomNodesSource, WebRandomNodesSource>();

            // Singletons - only one needed per app
            container.RegisterType<IChatEngine, ChatEngine>(new ContainerControlledLifetimeManager());
            container.RegisterType<ILogOnSource, WebLogOnSource>(new ContainerControlledLifetimeManager());
            container.RegisterType<ILogger, IsolatedStorageLogger>(new ContainerControlledLifetimeManager());
            container.RegisterType<IServerSettingsRepository, IsolatedStorageServerSettings>(new ContainerControlledLifetimeManager());
            container.RegisterType<IUISettingsRepository, IsolatedStorageUISettings>(new ContainerControlledLifetimeManager());
        }
    }
}
